import { methods, request } from '@/utils/request'; //设置自己的request路径

const actions = {
  getnoticeList: {
    //学生获取通知列表
    name: 'getnoticeList',
    url: '/api/freshSystem/student/selectNotifyList/',
  },
  getnoticeDetail: {
    //学生获取通知详情
    name: 'getnoticeDetail',
    url: '/api/freshSystem/student/selectNotifyById',
  },
  getfileDownload: {
    //下载附件
    name: 'getfileDownload',
    url: '/api/freshSystem/downloadFile/',
  },
  getfileUpload: {
    //填写回执带附件
    name: 'getfileUpload',
    url: '/api/freshSystem/student/receiptAttachedFile',
  },
  getNoticeReadAll: {
    //全部已读
    name: 'getNoticeReadAll',
    url: '/api/freshSystem/student/notifyList/readAll/',
  },
};

const customRequest = (action: any, token: any, formdata: any = null) => {
  const options: any = {
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      Accept: 'application/json',
      Authorization: localStorage.getItem('token') ? localStorage.getItem('token') : '',
    },
  };
  let url = action.url;
  switch (action.name) {
    case actions.getnoticeList.name: //学生获取通知列表
      options['method'] = methods.get;
      url += formdata;
      // console.log(url);
      break;
    case actions.getnoticeDetail.name: //学生获取通知详情
      options['method'] = methods.get;
      url += '?id=' + formdata.id + '&stuCode=' + formdata.stuCode;
      // console.log(url);
      break;
    case actions.getfileDownload.name: //下载附件
      options['method'] = methods.get;
      url += formdata;
      break;
    case actions.getfileUpload.name: //填写回执带附件
      options['method'] = methods.post;
      options['body'] = JSON.stringify(formdata);
      break;
    case actions.getNoticeReadAll.name: //全部已读
      options['method'] = methods.put;
      url += formdata;
      break;
    default:
  }
  return request(url, options);
};

export function getnoticeList(token: any, formdata: any) {
  //学生获取通知列表
  return customRequest(actions.getnoticeList, token, formdata);
}
export function getnoticeDetail(token: any, formdata: any) {
  //学生获取通知详情
  return customRequest(actions.getnoticeDetail, token, formdata);
}
export function getfileDownload(token: any, formdata: any) {
  //下载附件
  return customRequest(actions.getfileDownload, token, formdata);
}
export function getfileUpload(token: any, formdata: any) {
  //填写回执带附件
  return customRequest(actions.getfileUpload, token, formdata);
}
export function getNoticeReadAll(token: any, formdata: any) {
  //全部已读
  return customRequest(actions.getNoticeReadAll, token, formdata);
}
